package Controller.Employee;

import Dto.Employee;
import Service.EmployeeService;
import Service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "preUpdateEmployee", value = "/PreUpdateEmployee")
public class PreUpdateEmployee extends HttpServlet {
    private EmployeeService employeeService = new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    //预处理先(通过id)把修改的内容查询到employee对象中，然后把employee对象取出到新的jsp
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        try {
            Employee employee = employeeService.preUpdateEmployee(id);
            request.setAttribute("employee", employee);
            request.getRequestDispatcher("/updateEmployee.jsp").forward(request, response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
